import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sgy_flutter/ble/ble_manager.dart';
import 'package:sgy_flutter/extensions/get.dart';
import 'package:sgy_flutter/gen/assets.gen.dart';
import 'package:sgy_flutter/page/detail/logic.dart';
import 'package:sgy_flutter/page/detail/widget/ble_state_view.dart';
import 'package:sgy_flutter/page/detail/widget/ble_stream_view.dart';

import '../widget/device_data_view.dart';
import 'package:rxdart/rxdart.dart' as rx;

class DlsDoubleCenterView extends GetView<DetailLogic> {
  const DlsDoubleCenterView({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        border: Border.all(
          width: 0,
          color: Get.theme.primaryColor,
        ),
        color: Get.theme.primaryColor,
      ),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          // 功率,踏频,左右平衡
          Container(
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(28), topRight: Radius.circular(28)),
              border: Border(
                  bottom: BorderSide(color: Get.theme.primaryColor, width: 6)),
            ),
            padding: EdgeInsets.only(top: 24, bottom: 10, left: 12, right: 12),
            child: BleStreamView2(
                rightBleManager: controller.rightBleManager,
                bleManager: controller.bleManager,
                builder: (leftConnected, rightConnected, data) {
                  final connected = leftConnected || rightConnected;
                  String wrapper(String value) {
                    return data == null ? "-/-" : value;
                  }

                  printError(
                      info:
                          "leftConnected:$leftConnected, rightConnected:$rightConnected,${data?.power}");
                  return Column(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Row(
                        // mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                        children: [
                          DeviceDataView(
                              imagePath: Assets.image.iconLightning.path,
                              label: "功率/W".tr,
                              value:
                                  "${connected && data?.power != null ? data?.power : '--'}"),
                          Container(
                            width: 2,
                            color: Get.theme.dividerColor,
                            height: 50,
                          ),
                          DeviceDataView(
                              imagePath: Assets.image.iconFrequency.path,
                              label: "踏频/RPM".tr,
                              value:
                                  "${connected && data?.cadence != null ? data?.cadence : '--'}"),
                        ],
                      ),
                      leftConnected && rightConnected
                          ? Row(
                              // mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                              children: [
                                DeviceDataView(
                                  imagePath: null,
                                  label: "左右平衡/%".tr,
                                  value: wrapper(
                                      "${(data?.leftRightBalance ?? 0) ~/ 2}/${100 - (data?.leftRightBalance ?? 0) ~/ 2}"),
                                ),
                                Container(
                                  width: 2,
                                  color: Get.theme.dividerColor,
                                  height: 50,
                                ),
                                DeviceDataView(
                                    imagePath: null,
                                    label: "踩踏平顺度/%".tr,
                                    value: wrapper(
                                        "${data?.leftCadenceSmooth}/${data?.rightCadenceSmooth}")),
                                Container(
                                  width: 2,
                                  color: Get.theme.dividerColor,
                                  height: 50,
                                ),
                                DeviceDataView(
                                    imagePath: null,
                                    label: "扭矩有效性/%".tr,
                                    value: wrapper(
                                        "${data?.leftTorsionAvailability}/${data?.rightTorsionAvailability}")),
                              ],
                            ).marginOnly(top: 12, bottom: 12)
                          : Container()
                    ],
                  );
                },
                stream: controller.bleManager.dlsUploadModel),
          ),


        ],
      ),
    );
  }




}
